package com.api.custom.attendance.report;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;

import net.sf.json.JSONObject;
import weaver.hrm.User;
import weaver.hrm.company.SubCompanyComInfo;
import weaver.hrm.companyvirtual.SubCompanyVirtualComInfo;
import weaver.hrm.resource.ResourceComInfo;

/**
 * @author	Huangwm
 * @date  	2020年1月2日 下午11:00:44
 * @project	E9
 * @name	getHrmInfo
 * @package com.api.custom.attendance.report
 * @description	
 */
@Path("/attendance/report")
public class getHrmInfo {
	@GET
	@Path("/getHrm")
	@Produces(MediaType.TEXT_PLAIN)
	public static String getEmail(@Context HttpServletRequest request,@Context HttpServletResponse response){
		JSONObject object = new JSONObject();
		User user = null;
		try{
			HttpSession session = request.getSession();
			user = (User) session.getAttribute("weaver_user@bean");
			String uid = user.getUID() + "";
			ResourceComInfo rci = new ResourceComInfo();
			String subcompanyid = rci.getSubCompanyID(uid);
			SubCompanyComInfo subCompanyComInfo = new SubCompanyComInfo();
			//虚拟分部缓存信息
			SubCompanyVirtualComInfo subCompanyVirtualComInfo = new SubCompanyVirtualComInfo();
			String subcompanyname = "";
			if(Integer.parseInt(subcompanyid) < 0)
				//如当前用户是属于虚拟组织，则获取虚拟分部
				subcompanyname = subCompanyVirtualComInfo.getSubCompanyname(subcompanyid);
			else {
				subcompanyname = subCompanyComInfo.getSubCompanyname(subcompanyid);
			}
			
			object.put("userid", uid);
			object.put("subcompanyid", subcompanyid);
			object.put("subcompanyname", subcompanyname);
			object.put("subid1", user.getUserSubCompany1());
			object.put("subid2", user.getUserSubCompany2());
			object.put("subid3", user.getUserSubCompany3());
			object.put("subid4", user.getUserSubCompany4());
			object.put("depid", user.getUserDepartment());
			object.put("lastname", user.getLastname());
			object.put("email", user.getEmail());
			object.put("enddate", user.getEnddate());
			object.put("status", true);
		}catch(Exception e){
			object.put("status", false);
			object.put("code", "10001");
			object.put("msg", "失败");
		}
		
		return object.toString();
	}
}
